package cn.livingCloud.controller.user;

import cn.livingCloud.dto.MemberDto;
import cn.livingCloud.dto.MemberJsonDto;
import cn.livingCloud.dto.MemberListDto;
import cn.livingCloud.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 会员列表
 * Created by DingJie  on 2015/12/29.
 */
@Controller
@RequestMapping("/admin/wechat/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @RequestMapping("/list.htm")
    private String list(MemberListDto listDto, Model model) {
        memberService.load(listDto);
        model.addAttribute("listDto", listDto);
        return "wechat/member/list";
    }

    @RequestMapping("/change_state")
    public String stateChange(String uuid, boolean state, Model model) {
        MemberDto memberDto = memberService.uploadState(uuid, state);
        model.addAttribute("listDto", memberDto);
        return "wechat/member/list_item";
    }

    @RequestMapping("/find_member")
    @ResponseBody
    public List<MemberJsonDto> findEmployees(String key, Model model) {
        return memberService.findMembers(key);
    }

}
